<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>数组方法</title>
</head>

<body>

  <pre>
    变异方法：Vue 将数组方法进行了进一步封装，让这些方法具有响应式功能，
              只用这些方法对data中的数据进行修改以后，能够直接出发试图更新

              push()
              pop()
              shift()
              unshift()
              splice()
              sort()
              reverse()
    替换数组
            不会触发视图更新，会产生一个新的数组。需要把新的数组赋值给data中的数据，试图才会更新

            filter()
            concat() 
            slice()
  </pre>

  <div id="app">
    <input type="text" v-model='name'>
    <button @click='add'>添加</button>
    <button @click='del'>删除</button><br>
    <span>开始</span><input type="number" v-model.number='begin'>
    <span>结束</span><input type="number" v-model.number='end'>
    <button @click='handle'>截取</button>
    <p v-for='(item,index) in arr' :key='index'>{{item}}</p>
  </div>
  <script src="./js/vue.js"></script>
  <script>
    var vm = new Vue({
      el: '#app',
      data: {
        begin: '',
        end: '',
        name: '',
        arr: ['Tom', 'jerry', 'spike']
      },
      methods: {
        add() {
          this.arr.push(this.name)
          this.name = ''
        },
        del() {
          this.arr.pop()
        },
        handle() {

          this.arr = this.arr.slice(this.begin, this.end)
          this.begin = ''
          this.end = ''
        }
      }
    })
  </script>
</body>

</html>